using System;
using System.Collections.Generic;
using System.Text;
using BizTalkCop.Rules.Bases;
using Microsoft.FxCop.Sdk;
using Microsoft.BizTalk.ExplorerOM;

namespace BizTalkCop.Rules.Naming.Rules
{
    /// <summary>
    /// Rule verifying receive location names are correctly prefixed with their port name
    /// </summary>
    public class ReceiveLocationNamesShouldIndicatePortName : ApplicationRuleBase
    {
        /// <summary>
        /// Default constructor
        /// </summary>
        public ReceiveLocationNamesShouldIndicatePortName() : base("ReceiveLocationNamesShouldIndicatePortName") { }

        /// <summary>
        /// Checks if the receive location name is correctly prefixed
        /// </summary>
        /// <param name="application">Application to check</param>
        /// <returns>Problem collection</returns>
        protected override ProblemCollection Check(Application application)
        {
            foreach (ReceivePort port in application.ReceivePorts)
            {
                foreach (ReceiveLocation location in port.ReceiveLocations)
                {
                    if (!location.Name.StartsWith(port.Name))
                    {
                        Problems.Add(new Problem(GetNamedResolution("Prefix", location.Name, port.Name), application.Name));
                    }
                }
            }
            return Problems;
        }
    }
}
